package cn.kgc.javaweb.service.impl;

import cn.kgc.javaweb.dao.StudentDao;
import cn.kgc.javaweb.dao.impl.StudentDaoImpl;
import cn.kgc.javaweb.service.StudentService;
import cn.kgc.javaweb.vo.StudentVO;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/5/25
 * @Description:
 */
public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl();

    @Override
    public HashMap<String, Object> getPage(Integer page, Integer limit, String studentName, String clazz) {

        HashMap<String, Object> map = new HashMap<>();

        Integer start = (page-1)*limit;
        // 1. 查询当前页数据   搜索
        try {
            List<StudentVO>  studentVOS =  studentDao.getList(start,limit,studentName,clazz);
            // 2.查询数据的总条数   搜索
            Long count =  studentDao.getTotal(studentName,clazz);
            map.put("code",0);
            map.put("data",studentVOS);
            map.put("count",count);
            map.put("msg","查询成功");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            map.put("code",500);
            map.put("msg","查询失败");
        }
        return map;
    }
}
